package com.ambulance.project.manager.service.impl;

import com.ambulance.project.biz.service.MyCustomerService;
import com.ambulance.project.manager.domain.*;
import com.ambulance.project.manager.mapper.BizDispatchMapper;
import com.ambulance.project.manager.service.IBizDispatchService;
import com.ambulance.project.manager.utils.MgtCommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 调度记录基本信息Service业务层处理
 *
 * @author zr
 * @date 2020-05-11
 */
@Service
public class BizDispatchServiceImpl implements IBizDispatchService {

    @Autowired
    private BizDispatchMapper bizDispatchMapper;
    @Autowired
    private MgtCommonUtil mgtCommonUtil;
    @Autowired
    private MyCustomerService myCustomerService;
    @Autowired
    private BizDriverServiceImpl bizDriverService;
    @Autowired
    private BizDoctorServiceImpl bizDoctorService;
    @Autowired
    private BizNurseServiceImpl bizNurseService;
    @Autowired
    private BizClassServiceImpl bizClassService;
    @Autowired
    private BizPatientServiceImpl bizPatientService;
    @Autowired
    private BizCarServiceImpl bizCarService;

    /**
     * 查询调度记录基本信息
     *
     * @param dispatchID 调度记录基本信息ID
     * @return 调度记录基本信息
     */
    @Override
    public BizDispatch selectBizDispatchById(Long dispatchID) {
        return bizDispatchMapper.selectBizDispatchById(dispatchID);
    }

    /**
     * 查询调度记录基本信息
     *
     * @param dispatchID 调度记录基本信息ID
     * @return 调度记录基本信息
     */
    public BizDispatch selectBizDispatchById2(Long dispatchID) {
        final BizDispatch bizDispatch = bizDispatchMapper.selectBizDispatchById(dispatchID);
        final BizClass bizClass = bizClassService.selectBizClassById(bizDispatch.getClassID());
        final BizDoctor bizDoctor = bizDoctorService.selectBizDoctorById(bizDispatch.getDoctorID());
        final BizNurse bizNurse = bizNurseService.selectBizNurseById(bizDispatch.getNurseID());
        final BizDriver bizDriver = bizDriverService.selectBizDriverById(bizDispatch.getDriverID());
        final BizPatient bizPatient = bizPatientService.selectBizPatientById(bizDispatch.getPatientID());
        final BizCar bizCar = bizCarService.selectBizCarById(bizDispatch.getCarID());
        bizDispatch.setBizClass(bizClass);
        bizDispatch.setBizDoctor(bizDoctor);
        bizDispatch.setBizNurse(bizNurse);
        bizDispatch.setBizDriver(bizDriver);
        bizDispatch.setBizPatient(bizPatient);
        bizDispatch.setBizCar(bizCar);
        return bizDispatch;
    }

    /**
     * 查询调度记录基本信息列表
     *
     * @param bizDispatch 调度记录基本信息
     * @return 调度记录基本信息
     */
    @Override
    public List<BizDispatch> selectBizDispatchList(BizDispatch bizDispatch) {
        return bizDispatchMapper.selectBizDispatchList(bizDispatch);
    }

    /**
     * 新增调度记录基本信息
     *
     * @param bizDispatch 调度记录基本信息
     * @return 结果
     */
    @Override
    public int insertBizDispatch(BizDispatch bizDispatch) {
        return bizDispatchMapper.insertBizDispatch(bizDispatch);
    }

    /**
     * 修改调度记录基本信息
     *
     * @param bizDispatch 调度记录基本信息
     * @return 结果
     */
    @Override
    public int updateBizDispatch(BizDispatch bizDispatch) {
        return bizDispatchMapper.updateBizDispatch(bizDispatch);
    }

    /**
     * 批量删除调度记录基本信息
     *
     * @param dispatchIDs 需要删除的调度记录基本信息ID
     * @return 结果
     */
    @Override
    public int deleteBizDispatchByIds(Long[] dispatchIDs) {
        return bizDispatchMapper.deleteBizDispatchByIds(dispatchIDs);
    }

    /**
     * 删除调度记录基本信息信息
     *
     * @param dispatchID 调度记录基本信息ID
     * @return 结果
     */
    @Override
    public int deleteBizDispatchById(Long dispatchID) {
        return bizDispatchMapper.deleteBizDispatchById(dispatchID);
    }

    @Override
    public int doDispatcher(BizDispatch bizDispatch) {
        int uid = mgtCommonUtil.getMgtUserLoginResult().getUid();
        myCustomerService.scheduleCar(bizDispatch.getPatientID().intValue(), bizDispatch.getDriverID().intValue(),
                bizDispatch.getClassID().intValue(), bizDispatch.getCarID().intValue(), uid);
        return 1;
    }
}
